// 对小程序中的发送请求进行二次封装

const BASE_URL = "http://106.75.16.42"

// ajax  post  get  

// wx.request 默认给后端的是Json数据  "content-type":"aplication/json"
// 后端需要表单数据    "content-type":"aplication/x-www-form-urlencode"
const post = (url,data)=>{
    return new Promise((resolve, reject)=>{
        wx.request({
          url: BASE_URL+url,
          data:{...data},
          method:"POST", 
          timeout:50000,
          header:{
            "content-type":"application/x-www-form-urlencoded"
          },
          success(res){
              resolve(res.data)
          },
          fail(err){
              reject(err)
          }
        })
    })
}

const get = (url,data)=>{
    return new Promise((resolve, reject)=>{
        wx.request({
          url: BASE_URL+url,
          data:{...data},
          method:"GET", 
          timeout:50000,
          header:{
            "content-type":"application/x-www-form-urlencoded"
          },
          success(res){
              resolve(res.data)
          },
          fail(err){
              reject(err)
          }
        })
    })
}

module.exports = {
    post,get
}





























